package com.swjd.bean;
import java.sql.*;
public class ticket {
	  private String ticketid;//列车号
	  private String startplace;//始发地
	  private String destination; //终点站
	  private String type;//列车类型
	  private String trainid;//票号
	  private double price;//价格
	  private int seat;//座位
      private String startdate;//日期

                                                                   
	  public String getticketId() {
	    return ticketid;
	  }
	  public void setticketId(String tid) {
	    this.ticketid = tid;
	  }
	  public String getStartplace() {
	    return startplace;
	  }
	  public void setStartplace(String sp) {
	    this.startplace = sp;
	  }
	  public String getDestination() {
	    return destination;
	  }
	  public void setDestination(String md) {
	    this.destination = md;
	  }
	  public String getStartdate() {
		    return startdate;
		  }
		  public void setStartdate(String sd) {
		    this.startdate = sd;
		  }
	  public void setType(String t) {
		    this.type=t;
		  }
	  public String getType() {
		    return type;
		  }
	  public void setTrainid(String trainid) {
		    this.trainid =trainid;
		  }
	  public String getTrainid() {
		    return trainid;
		  }
	  public void setSeat(int seat) {
		    this.seat =seat;
		  }
	  public int getSeat() {
		    return seat;
		  }
	  public double getPrice() {
		    return price;
		  }
	  public void setPrice(double jg) {
		    this.price = jg;
		  }

	  
	  
	  public boolean hasLogin(String tid){   //检查该车票是否已经存在 
	  	boolean f=true;
	   String sql="select ticket_id from ticket where ticket_id ='"+tid+"'";
	  	sqlBean db =new sqlBean();
	  	try{
	  	ResultSet rs=db.executeQuery(sql);
	  	if(rs.next()){ f=false;}
	  	else{ f=true;}
	  	}catch(Exception e){ e.getMessage();}
	  	return f;
	  	                       }
	  	                       
	  public ResultSet  getTicket(){
			String sql="select * from ticket ";
			sqlBean db= new sqlBean();
			ResultSet rs = db.executeQuery(sql);
			 return rs;
			                         } 
	  public void addBook(String start,String dest,String userid,double sub,int count,double afford)  {
	    String sql="insert into book(start_station,dest_station,user_id,subscription,countnumber,afford)  "+	
	            "VALUES('"+start+"','"+dest+"','"+userid+"','"+sub+"'," +
	            "'"+count+"','"+afford+"')";
	            sqlBean db =new sqlBean();
	          
	               db.executeInsert(sql);
	        }
			                         
    /*public void updateTicket(){
	    	String sql="update ticket SET " +
	    			   "startplace='"+startplace+"',destination='"+destination+"'," +
	    			   "starttime='"+starttime+"',remain='"+shengyu+"'," +
	    			   "price='"+price+"',seat='"+seat+"',train_id='"+trainid+"'"+
	                   " where ticket_id='"+ticketid+"' ";
	                 sqlBean db= new sqlBean();
	                 db.executeInsert(sql);
	                 
	    	}	   */ 	
	  public void updateBook(String userid,int num){//从Book表中更新订票数目
		  String sql="update book SET countnumber='"+num+"' " +
          " where user_id='"+userid+"' and start_station='"+startplace+"' and dest_station='"+destination+"'";
	    	sqlBean db= new sqlBean();
	    	db.executeDelete(sql);
	    	}  
	  public void deleteBook(String userid){//从Book表中删除订票信息
		    
	    	String sql="delete from book  where user_id='"+userid+"' and start_station='"+startplace+"' and dest_station='"+destination+"'";
	    	sqlBean db= new sqlBean();
	    	db.executeDelete(sql);
	    	}   
	  public void deleteTicket(){
	    
	    	String sql="delete from ticket where ticket_id ='"+ticketid+"'";
	    	sqlBean db= new sqlBean();
	    	db.executeDelete(sql);
	    	}                       
	  	       
	  public int deleteTicket(String ticketid){
	    	int num=0;
	    	String sql="delete from ticket where ticket_id ='"+ticketid+"'";
	    	sqlBean db= new sqlBean();
	    	num=db.executeDelete(sql);
	    	return num;
	    	}                        	                       
      public void addTicket()  {
	    String sql="insert into ticket(ticket_id,start_station,dest_station,startdate,price,type,seat,train_id)  "+	
	            "VALUES('"+ticketid+"','"+startplace+"','"+destination+"','"+startdate+"'," +
	            "'"+price+"','"+type+"','"+seat+"','"+trainid+"')";
	            sqlBean db =new sqlBean();
	          
	               db.executeInsert(sql);
	        }
      public void updateTrain(int ticketnum){
	    	String sql="update train SET ticket_num='"+ticketnum+"' " +
	                   " where train_id='"+trainid+"' ";
	                 sqlBean db= new sqlBean();
	                 db.executeInsert(sql);
	                 
	    	}
}
